Fix up event-construction in tests ahead of the Rust event port#19781
Merged
Conversation
Prepare for porting the event class into Rust, where the constructor strictly validates that all format-required fields (depth, hashes, origin_server_ts, auth_events, prev_events, ...) are present. Most tests build minimal dicts that omit these fields because they only care about the fields the test exercises. Introduce make_test_event and make_test_pdu_event, which layer format-version-aware defaults on top of caller-supplied fields so individual tests don't need to spell out every required key.
ed2418d to
2bdad53
Compare
Switch test sites that build EventBase/PDU instances over to make_test_event / make_test_pdu_event so they pick up the defaults the strict (Rust-bound) constructor will require.
…rectly Some test fixtures construct event/PDU dicts inline rather than via make_test_event — typically because they then run them through add_hashes_and_signatures or otherwise depend on the exact dict shape. Add the format-required fields (depth, hashes, auth_events, prev_events, ...) inline in those cases so they keep working under the strict (Rust-bound) constructor.
84d9eb6 to
a505bb5
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR is a test-infrastructure cleanup ahead of porting Event to Rust. The Rust constructor will validate that required event fields are present, so the test suite is being updated to consistently include those fields when fabricating fake events. A new tests/test_utils/event_builders.py module centralizes the defaults, and call sites across the test suite are switched from make_event_from_dict / event_from_pdu_json to the new helpers make_test_event / make_test_pdu_event.
Changes:
- Add
tests/test_utils/event_builders.pyprovidingmake_test_eventandmake_test_pdu_eventthat layer in room-version-aware required-field defaults (type,sender,content,depth,origin_server_ts,hashes,prev_events,room_id, andauth_events/prev_state_eventsdepending on MSC4242). - Migrate ~30 test files to use the new helpers; remove direct imports of
make_event_from_dictandevent_from_pdu_jsonin those tests. - Update test expectations (e.g.
_flatten_dict,prune_event, event field whitelisting) to account for the additional default fields now present on test events.
Reviewed changes
Copilot reviewed 28 out of 28 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_utils/event_builders.py | New helpers with format-version aware defaults. |
| tests/test_state.py | Switch create_event to make_test_event. |
| tests/test_event_auth.py | Migrate many event constructions to make_test_event. |
| tests/storage/test_sliding_sync_tables.py | Use make_test_event for fake kick event. |
| tests/storage/test_msc4242_state_dag.py | Use make_test_event in _make_event. |
| tests/storage/test_events.py | Use make_test_pdu_event for remote PDU fakes. |
| tests/storage/databases/main/test_events_worker.py | Use make_test_event; persist event.get_dict() JSON. |
| tests/state/test_v21.py | Add hashes default to event dict. |
| tests/state/test_v2.py | Migrate to make_test_event; use keyword room_version. |
| tests/rest/client/test_third_party_rules.py | Add hashes to federation event dict. |
| tests/rest/client/sliding_sync/test_sliding_sync.py | Use make_test_event for remote invite. |
| tests/push/test_push_rule_evaluator.py | Use make_test_event; update _flatten_dict expectations. |
| tests/push/test_presentable_names.py | Replace FrozenEvent with make_test_event; return type widened. |
| tests/handlers/test_sync.py | Use make_test_pdu_event for call invite PDUs. |
| tests/handlers/test_room_summary.py | Use make_test_event for fed invite. |
| tests/handlers/test_room_policy.py | Migrate event constructions to make_test_event. |
| tests/handlers/test_room_member.py | Use make_test_pdu_event for invite events. |
| tests/handlers/test_federation.py | Migrate to make_test_event/make_test_pdu_event. |
| tests/handlers/test_federation_event.py | Migrate event constructions. |
| tests/federation/transport/test_client.py | Add common required fields to parser test inputs. |
| tests/federation/test_federation_server.py | Migrate to new helpers. |
| tests/federation/test_federation_out_of_band_membership.py | Migrate to new helpers. |
| tests/federation/test_federation_client.py | Add depth defaults; dedupe duplicate depth. |
| tests/federation/test_federation_base.py | Add required fields to a test event dict. |
| tests/events/test_utils.py | Switch MockEvent to make_test_event with defaults; update prune_event expectations. |
| tests/events/test_auto_accept_invites.py | Use make_test_pdu_event for invite events. |
| tests/crypto/test_event_signing.py | Migrate to make_test_event. |
| changelog.d/19781.misc | Changelog entry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This can be replaced with a direct call to `make_test_event`
MadLittleMods
approved these changes
May 14, 2026
FrenchGithubUser
pushed a commit
to famedly/synapse-upstreaming
that referenced
this pull request
Jun 12, 2026
…ent-hq#19781) When we port the `Event` class to Rust, the constructor will check for the existence of required fields. To support that, we tidy up the test code where we construct fake events to add all the required fields. There should be no behavioural changes. Review commit-by-commit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When we port the
Eventclass to Rust, the constructor will check for the existence of required fields. To support that, we tidy up the test code where we construct fake events to add all the required fields.There should be no behavioural changes.
Review commit-by-commit.